<?php
/**
 * Created by PhpStorm.
 * User: yangyulu
 * Date: 2020/3/10
 * Time: 上午11:56
 */
class questionsModel extends Model{
    public function medal($userId){

        $config=self::model("bonus_config")->getOne(["id=?"],[8]);
        $info=self::model("users")->getOne(["id=?"],[$userId]);
        $data['user_id']=$userId;
        $data['money']=$config["integral"];
        $data['has_money']=$info["integral"]+$config["integral"];
        $data['type']=1;
        $data['water_type']=$config['type'];
        $data['integral_desc']=$config['name'];
        $data['add_time']=date("Y-m-d H:i:s",time());
        $res=self::model("integral_water")->insert($data);
        if($res){
            $u_add["integral"]=$info["integral"]+$config["integral"];
            $u_add["total_integral"]=$info["total_integral"]+$config["integral"];
            self::model("users")->update($u_add,"id=?",$userId);
        }
        $redis=new Cache_Redis();
        $key="user_info_".$userId;
        $redis->getConnection()->hIncrBy($key,"integral",$config["integral"]);
        $redis->getConnection()->hIncrBy($key,"total_integral",$config["integral"]);

        $count=$this->where(["user_id=?","status=?"],[$userId,1])->count();
        switch ($count){
            case 10:
                self::model("user_medal")->insert(["medal_id"=>3,"user_id"=>$userId,"add_time"=>date("Y-m-d  H:i:s",time())]);
                break;
            default:
                break;
        }
    }
}